package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShopController")
@RequestMapping("/admin/shop")
public class ShopController {
    public static String KEY = "SHOP_STATUS";

    @Autowired
    RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    public Result updateShopStatus(@PathVariable String status){
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success("设置成功");
    }
    @GetMapping("/status")
    public Result<Integer> queryShopStatus(){
        Object obj = redisTemplate.opsForValue().get(KEY);
        Integer val = (obj instanceof String) ? Integer.parseInt((String) obj) : (Integer) obj;
        if(val == null){
            redisTemplate.opsForValue().set(KEY,"0");
            val = 0;
        }
        return Result.success(val);
    }
}
